package com.hevs.samplewebapp.server.service;

import java.util.List;

import com.hevs.samplewebapp.server.dao.DAOFactory;
import com.hevs.samplewebapp.server.entities.InternalMessage;
import com.hevs.samplewebapp.server.entities.User;

/**
 * Service for internal messaging between users
 * 
 * @author Arnaud Durand
 * @date 14.03.12
 */
public class InternalMessageService extends Service {


	/**
	 * Default constructor
	 */
	public InternalMessageService() {
		super();
	}
	
	/**
	 * Constructor with specified DAOFactory
	 * 
	 * @param daoFactoryInstance
	 *            factory which is called for DAO instantiation
	 */
	public InternalMessageService(DAOFactory daoFactoryInstance){
		super(daoFactoryInstance);
	}
	
	/**
	 * Send message from the local user to the remote user
	 * 
	 * @param local sender user
	 * @param remote receiver user
	 * @param mail message to be sent
	 */
	public void sendMessage(User local, User remote, InternalMessage mail){
		getInternalMessageDAO().send(local, remote, mail);
	}
	
	/**
	 * Get all the messages received of the specified user
	 * 
	 * @param local target user
	 * @return list of messages
	 */
	public  List<InternalMessage> getAllMessages(User local){
		return getInternalMessageDAO().getAll(local);
	}
	
	/**
	 * Delete the specified message
	 * 
	 * @param mail message to delete
	 */
	public void removeMessage(InternalMessage mail){
		getInternalMessageDAO().remove(mail);
	}
	
	

}
